package com.example.bookstore.mapper;

import com.example.bookstore.entity.Ordered;
import com.example.bookstore.entity.OrderLink;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import java.util.List;

@Mapper
@Repository
public interface OrderMapper {

    /**
     * 查询所有订单
     * @return
     */
    @Select("select * from ordered")
    List<Ordered> findAllOrder();


    /**
     * 生成主订单
     * @param order
     * @return
     */
    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into ordered values (0,#{userId},#{userName},#{address},#{phone},#{date},#{status})")
    Integer createOrder(Ordered order);


    /**
     * 生成orderlink订单
     * @param orderLink
     * @return
     */
    @Insert("insert into orderlink values (0,#{orderId},#{bookId},#{bookImage},#{bookName},#{bookPrice},#{bookNumber})")
    Integer createOrderLink(OrderLink orderLink);


    /**
     * 根据订单id查询所有关于它的oredrlink
     * @param orderedId
     * @return
     */
    @Select("select * from orderlink where order_id = #{orderedId}")
    List<OrderLink> findOrderLinks(Integer orderedId);


    /**
     * 根据userId查询订单
     * @param id
     * @return
     */
    @Select("select * from ordered where user_id = #{id}")
    Ordered queryMyOrdered(Integer id);
}
